home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MOUSE.SWG / 0019_TP7 Mouse Unit.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-05  |  4KB  |  80 lines

  1. Program MouseDemo;   { I just learned this little piece of wizardry }
  2. Uses                 { so I thought I would pass it on -- have fun! }
  3.   Crt,Dos,Drivers;
  4. Type
  5.   CharType=Set Of Char;
  6. Var
  7.   Key:Char; ValidKeys:CharType;
  8.   Button_Status,Mouse_X,Mouse_Y,ButtonPressed,X,Y:Word;
  9. Procedure GetMouse (Var Button_Status,Mouse_X,Mouse_Y:Word;
  10.                                               Monitor:Word);
  11. Var                       { --------------------------------------- }
  12.   Regs:Registers;         { Button_Status     0 = no button pressed }
  13. Begin                     { Mouse_X           X coordinate          }
  14.   Regs.AX:=3;             { Mouse_Y           Y coordinate          }
  15.   Intr($33,Regs);         { Monitor           0 = off  1 = on       }
  16.   Button_Status:=Regs.BX; { Monitor can be set to 1 While coding to }
  17.   Mouse_X      :=Regs.CX; { display Button_Status,   Mouse_X,   and }
  18.   Mouse_Y      :=Regs.DX; { Mouse_Y in the upper-left corner of the }
  19.   If (Monitor=1) Then     { screen                                  }
  20.     Begin                 { --------------------------------------- }
  21.       TextBackGround(7); TextColor(8); GotoXY(1,1);
  22.       Write('             '); GotoXY(1,1);
  23.       Write(Button_Status:2,Mouse_X:5,Mouse_Y:5); Delay(100)
  24.     End
  25. End;
  26. Procedure GetEvent;
  27. Label
  28.   ExitLoop;
  29. Begin
  30.   TextBackGround(0); ClrScr; TextColor(7);
  31.   GotoXY(26,12); Write('Continue? [Y] or [N]? ');
  32.   ValidKeys:=[#89,#78];          { accept only Y or N as valid keys }
  33.   Key:=#255;                     { initialize Key to a nonvalid key }
  34.   Repeat
  35.     While (Not KeyPressed) Do
  36.       Begin
  37.         GetMouse(Button_Status,Mouse_X,Mouse_Y,0);
  38.         Repeat                               { ^  turns monitor off }
  39.           GetMouse(ButtonPressed,X,Y,0) { X & Y are dummy variables }
  40.         Until (KeyPressed) Or (ButtonPressed<>Button_Status);
  41.     { Repeat ^ Until "waits" until a change in Button_Status occurs }
  42.     { this eliminates a "slow" click from being processed as two or }
  43.     { more clicks                                                   }
  44.         If (Button_Status>0) THEN { a mouse button has been pressed }
  45.           Begin { convert mouse clicks into corresponding key codes }
  46.             If      (Mouse_X=288) And (Mouse_Y=88) Then Key:=#89
  47.             Else If (Mouse_X=344) And (Mouse_Y=88) Then Key:=#78;
  48.             If      (Key In ValidKeys)             Then Goto ExitLoop
  49.           End                              { exit the loop if valid }
  50.       End;                                 { key codes are received }
  51.     Key:=Upcase(ReadKey) { get keyboard event if KeyPressed is true }
  52.   Until (Key In ValidKeys);
  53.   ExitLoop: TextBackGround(0); ClrScr; TextColor(7);
  54.   If Key=#89 Then
  55.     Begin
  56.       Randomize;
  57.       X:=Random(61)+10;      { pick a random X column from 10 to 60 }
  58.       Y:=Random(21)+ 3;      { pick a random Y row    from  3 to 23 }
  59.       GotoXY(X,Y);     Write(#177);
  60.       GotoXY(X-5,Y+1); Write('Click here!');
  61.               { the X column and Y row numbers must be converted to }
  62.               { X and Y coordinates by multiplying the column & row }
  63.               { numbers by 8 and then subtracting 8 from that value }
  64.       Repeat  { for example:  column 40, row 10 converts to 312, 72 }
  65.         GetMouse(Button_Status,Mouse_X,Mouse_Y,1)
  66.                                              { ^   turns monitor on }
  67.       Until(Button_Status>0) And (Mouse_X=X*8-8) And (Mouse_Y=Y*8-8);
  68.       GetEvent                   {        ^^^^^               ^^^^^ }
  69.     End;                         { X coordinate        Y coordinate }
  70.   HideMouse; ClrScr
  71. End;
  72. Begin
  73.   InitEvents;
  74.         { sets the "hide counter" to zero and displays mouse cursor }
  75.         { use ShowMouse to decrement the hide counter               }
  76.         { use HideMouse to increment the hide counter               }
  77.         { when hide counter equals zero the mouse cursor is visible }
  78.   GetEvent
  79. End.
  80.